#!/bin/bash

####### A test script for the programs. #########

N_INPUTS=10		# number of input files
N_EXECS=10		# number of times to execute each input
INPUTS=./inputs		# directory with inputs
OUTPUTS=./outputs	# directory for outputs
N_THREADS=4		# number of threads for fixed threads analysis
N_THREADS_MAX=32 # maximum number of threads for variable number of threads analysis

printf '\n'
echo "Running script test for the $N_INPUTS first input files and $N_EXECS executions for each one of these input files."
printf '\n'

# running sequential
echo "Running sequential program..."
for ((i = 1; i <= $N_INPUTS; i++))
do 
	echo "running input$i..."
	echo "input$i:" >> $OUTPUTS/seq.times
	echo "input$i:" >> $OUTPUTS/seq.out 
	for ((j = 1; j <= $N_EXECS; j++))
	do
		/usr/bin/time -o $OUTPUTS/seq.times -a -f "%e" ./build/seq < $INPUTS/input$i >> $OUTPUTS/seq.out 
	done
done

# running parallel for fixed number of threads
printf '\n'
echo "Running parallel program number of threads fixed in $N_THREADS..."
for ((i = 1; i <= $N_INPUTS; i++))
do 
	echo "running input$i..."
	echo "input$i:" >> $OUTPUTS/par.times
	echo "input$i:" >> $OUTPUTS/par.out
	for ((j = 1; j <= $N_EXECS; j++))
	do
		/usr/bin/time -o $OUTPUTS/par.times -a -f "%e" ./build/par $N_THREADS < $INPUTS/input$i >> $OUTPUTS/par.out
	done
done

# running parallel for variable number of threads
printf '\n'
echo "Running parallel program for different number of threads (for input8) 1, 2, 4, 6...."
for ((i = 1; i <= $N_THREADS_MAX; i += 2))
do 
	if [ $i == 3 ]; then i=2; fi;
	echo "number_of_threads = $i.." 
	/usr/bin/time -o $OUTPUTS/par-threads.times -a -f "%e" ./build/par $i < $INPUTS/input8 >> $OUTPUTS/par-threads.out
done

# running 
echo "Running analysis program to calculate some statistical measures."
./build/analysis seq $N_INPUTS $N_EXECS > $OUTPUTS/analysis.seq
./build/analysis par $N_INPUTS $N_EXECS > $OUTPUTS/analysis.par

echo "Script test finished."
